<template>
	<view>
		<view class="login">
			<input type="text" v-model="username" placeholder="账号" />
			<input type="text" v-model="password" placeholder="密码" />
			<button @click="login()">登录</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username:'',
				password:''
			}
		},
		methods: {
			login(){
				// console.log(this.username,this.password)
				let url=`/1.1/classes/people?where={"username":"${this.username}"}`
					this.$get(url).then(res=>{
						uni.stopPullDownRefresh()
						
						if(res.results.length>0){
							if(this.password!==res.results[0].password){
								console.log("密码错误请重新输入")
								// console.log(this.password,res.results[0].password)
							}
							else if(this.password===res.results[0].password){
								console.log("登录成功")
								uni.setStorageSync('username', this.username);
								uni.switchTab({
								    url: '/pages/index/index',
									
								})
								// let a=uni.getStorageSync("username")
								// console.log(a)
							}
						}
						else{
							console.log("用户名输入错误或未注册")
						}
					})
				
					
			}
		}
	}
</script>

<style>
.login{
	width: 280px;
	height: 180px;
	margin: 0 auto;
	/* border: 1px solid black; */
	margin-top: 100px;
}
.login input{
	margin-top: 20px;
	/* border: 1px solid black; */
}
.login button{
	margin-top: 20px;
}
</style>
